//验证码
function ranCode() {
    codeArr = [];
    for (var i = 0; i < 4; i++) {
        var index = Math.floor(Math.random() * leg.length);
        var char = leg[index]
        if (codeArr.indexOf(char) == -1) {
            codeArr.push(char);
        } else {
            i--;
        }
    }
    return codeArr.join("");
}


//创建cookie
function setCookie(key, value, day, path = "/") {
    var date = new Date();
    date.setDate(date.getDate() + day);
    document.cookie = key + "=" + value + ";expires=" + date.toUTCString() + ";path=" + path;
}

//获取cookie
function getCookie(key) {
    var val;
    var arr = document.cookie.split("; ");
    // console.log(arr);
    for (var i = 0; i < arr.length; i++) {
        var item = arr[i];
        var k = item.split("=")[0];
        if (k == key) {
            val = item.split("=")[1];
            break;
        }
    }
    return val;
}

//url searsh解析
function urlParse() {
    var search = location.search;
    search = search.substring(1);
    var seaObj = {};
    var seaDataArr = search.split("&");
    for (var i in seaDataArr) {
        var seaDateArr1 = seaDataArr[i].split("=");
        var key = seaDateArr1[0];
        var val = seaDateArr1[1]
        seaObj[key] = val;
    }
    return seaObj;
}